package com.cms.service.Impl;

import com.cms.dto.SearchDTO;
import com.cms.entity.Student;
import com.cms.mapper.StudentMapper;
import com.cms.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class StudentServiceImpl implements StudentService {


    @Resource
    private StudentMapper studentMapper;

    @Override
    public Integer save(Student student) {
        return studentMapper.save(student);
    }

    @Override
    public List<Student> list() {
        return studentMapper.list();
    }

    @Override
    public Integer delete(Integer sid) {
        return studentMapper.delete(sid);
    }

    @Override
    public List<Student> search(SearchDTO searchDTO) {
        if (searchDTO.getKeywords() == null || searchDTO.getKeywords().equals("")) {
            return studentMapper.list();
        }

        List<Student> students = new ArrayList<>();

        switch (searchDTO.getType()) {
            case 1:
                students = studentMapper.searchByPhone(searchDTO.getKeywords());
                break;
            case 2:
                students = studentMapper.searchByName(searchDTO.getKeywords());
                break;
        }
        return students;

    }

    @Override
    public Integer update(Student student) {
        return studentMapper.update(student);
    }
}
